{{template "admin/header.html"}}
<title>{{.urlPathParam}} - gpress</title>
{{template "admin/bodystart.html"}}

{{ $tableFiled := tableFiled .urlPathParam }}
{{$path := .urlPathParam}}
<section class="section">
	<!-- 分页隐藏域 -->
	<input type="hidden" id="totalCount" value="{{.page.TotalCount}}">
	<input type="hidden" id="pageCount" value="{{.page.PageCount}}">
	
	<div class="container">
		<!-- 搜索表单 -->
		<form id="listForm" class="field is-horizontal" action="{{basePath}}admin/{{.urlPathParam}}/list" method="GET">
			<div class="field-body">
				<div class="field">
					<div class="control">
						<input class="input" type="text" name="q" placeholder="输入搜索内容...">
						<input type="hidden" id="pageNo" name="pageNo" value="{{.page.PageNo}}">
					</div>
				</div>
				<div class="field">
					<div class="control">
						<button class="button is-primary" type="submit">搜索</button>
						<a href="{{basePath}}admin/{{.urlPathParam}}/save" class="button is-primary"
							type="submit">新增</a>
					</div>
				</div>
			</div>
		</form>

		<!-- 列表 -->
		<div class="table-content">
			<table class="table is-hoverable is-fullwidth">
				<thead>
					<tr>
						<!-- 循环表头 -->
						{{ range $tableFiled }}
						<th>{{.FieldName}}</th>
						{{end }}
						<th class="pos-sticky">操作</th>
					</tr>
				</thead>
				<tbody>
					<!-- 循环所有的数据 -->
					{{ range $i,$v := .data }}
					<tr>
						<!-- 循环表头,需要和表格的表头对应 -->
						{{ range $tableFiled }}
						<!-- 获取每一列的值 -->
						<td> {{ index $v .FieldCode }}</td>
						{{end }}
						<td class="pos-sticky">
							<a class="button is-success is-light is-small"
								href="{{basePath}}admin/{{$path}}/update?id={{$v.id}}">编辑</a>
							<a class="button is-link is-light is-small"
								href="{{basePath}}admin/{{$path}}/look?id={{$v.id}}">查看</a>
							<input type="button" class="button is-danger is-small" onclick="deleteFunc(this.id)"
								id="{{$v.id}}" value="删除" />
						</td>
					</tr>
					{{end }}
				</tbody>
			</table>
		</div>
	</div>
	<!-- 分页条 -->
	<div class="page"></div>
</section>
<script>
console.log($('#PageCount').val())
	$.pageInit({
		container: '.page', //容器：默认page
		countPage: $('#pageCount').val(), //一共有多少页
		showPageCount: $('#pageCount').val(), //显示多少个分页按钮
		nowPage: $('#pageNo').val(), //当前是第几页
		count: $('#totalCount').val(), //数据总数
		callBack: function(data) {
			//当前的页码
			$('#pageNo').val(data)
			$('#listForm').submit()
			console.log('当前的页码为：' + data)
		}
	})

function deleteFunc(id) {
		$.confirm({
			useBootstrap: false,
			title: '提示',
			content: '确认删除？',
			boxWidth: '400px',
			type: 'red',
			buttons: {
				'确定': function() {
					$.ajax({
						type: 'Post',
						url: '{{basePath}}admin/{{$path}}/delete',
						data: { id: id },
						success: function(res) {
							if (res.statusCode === 1) {
								location.reload()
							}
						}
					})
				},
				'取消': function() {}
			}
		})

	}
</script>

{{template "admin/bodyend.html"}}
